package com.yasaka.stock.controller;

import com.yasaka.stock.exception.MyException;
import com.yasaka.stock.model.TWebResult;
import com.yasaka.stock.service.FileService;
import com.yasaka.stock.service.MessageService;
import com.yasaka.stock.service.MlpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(value = "local", tags = {"本地服务"})
@RestController
public class LocalController {

    //    @Autowired
//    private MlpFeignClient mlp;
//    @RequestMapping(value = "/getOnLineCountWord1", method = RequestMethod.POST)
    //    @HystrixCommand(fallbackMethod = "getOnLineCountWord1", commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000")
//    })
//    public TWebResult getOnLineCountWord(String aText) {
//        //HystrixThreadPoolProperties.Setter().withCoreSize(10);
//        return mlpService.getOnLineCountWord(aText);
//    }

    @Autowired
    private MessageService messageService;

    @Autowired
    private MlpService mlpService;

    @Autowired
    private FileService fileService;

    @ApiOperation(value = "字数统计", notes = "传入文本内容获取字数统计结果")
    @RequestMapping(value = "/getOnLineCountWord", method = RequestMethod.POST)
    public TWebResult getOnLineCountWord(@ApiParam(name = "aText", value = "文本内容", required = true) @RequestParam String aText) {
        return mlpService.getOnLineCountWord(aText);
    }

    @ApiOperation(value = "提取日本人名", notes = "传入文本内容提取日本人名")
    @RequestMapping(value = "/getOnlineJapaneseName", method = RequestMethod.POST)
    public TWebResult getOnlineJapaneseName(@ApiParam(name = "aText", value = "文本内容", required = true) @RequestParam String aText) {
        return mlpService.getOnlineJapaneseName(aText);
    }

    @ApiOperation(value = "提取英译人名", notes = "传入文本内容提取英译人名")
    @RequestMapping(value = "/getTranslatedName", method = RequestMethod.POST)
    public TWebResult getTranslatedName(@ApiParam(name = "aText", value = "文本内容", required = true) @RequestParam String aText) {
        return mlpService.getTranslatedName(aText);

    }

    @ApiOperation(value = "提取中文人名", notes = "传入文本内容提取中文人名")
    @RequestMapping(value = "/getChineseName", method = RequestMethod.POST)
    public TWebResult getChineseName(@ApiParam(name = "aText", value = "文本内容", required = true) @RequestParam String aText) {
        return mlpService.getChineseName(aText);

    }

    @ApiOperation(value = "提取拼音", notes = "传入文本内容提取拼音")
    @RequestMapping(value = "/getPinyinForFileId", method = RequestMethod.POST)
    public TWebResult getPinyinForFileId(@ApiParam(name = "aText", value = "文本内容", required = true) @RequestParam String aText) {
        return mlpService.getPinyinForFileId(aText);
    }


    @ApiOperation(value = "提取机构名称", notes = "传入文本内容提取机构名称")
    @RequestMapping(value = "/getOrganization", method = RequestMethod.POST)
    public TWebResult getOrganization(@ApiParam(name = "aText", value = "文本内容", required = true) @RequestParam String aText) {
        return mlpService.getOrganization(aText);
    }

    @ApiOperation(value = "google翻译", notes = "传入文本内容、源语种、目标语种获取对应译文")
    @RequestMapping(value = "/googleTranslation", method = RequestMethod.POST)
    public TWebResult googleTranslation(@ApiParam(name = "aStr", value = "文本内容", required = true) @RequestParam String aStr,
                                        @ApiParam(name = "aFrom", value = "源语种", required = true) @RequestParam String aFrom,
                                        @ApiParam(name = "aTo", value = "目标语种", required = true) @RequestParam String aTo) {
        return mlpService.googleTranslation(aStr, aFrom, aTo);
    }

    @ApiOperation(value = "提取数量词", notes = "传入文本内容提取数量词")
    @RequestMapping(value = "/getNumberAndQuantifier", method = RequestMethod.POST)
    public TWebResult getNumberAndQuantifier(@ApiParam(name = "aText", value = "文本内容", required = true) @RequestParam String aText) {
        return mlpService.getNumberAndQuantifier(aText);
    }

    @ApiOperation(value = "通过百度获取源语种", notes = "传入文本内容通过百度获取源语种")
    @RequestMapping(value = "/getStrlang", method = RequestMethod.POST)
    public TWebResult getStrlang(@ApiParam(name = "aStr", value = "文本内容", required = true) @RequestParam String aStr) {
        return mlpService.getStrlang(aStr);
    }

    @ApiOperation(value = "发送短信服务(容联云通讯)", notes = "发送短信服务(容联云通讯)")
    @RequestMapping(value = "/sendSms", method = RequestMethod.POST)
    public boolean sendSms(@ApiParam(name = "planform", value = "平台", required = true) @RequestParam String planform,
                           @ApiParam(name = "templateId", value = "模板ID", required = true) @RequestParam String templateId,
                           @ApiParam(name = "mobile", value = "电话号码", required = true) @RequestParam String mobile,
                           @ApiParam(name = "info", value = "内容信息", required = true) @RequestParam String info) throws MyException {
        return messageService.sendSms(planform,templateId,mobile,info);
    }

    @ApiOperation(value = "上传远程文件到七牛", notes = "上传远程文件到七牛")
    @RequestMapping(value = "/uploadRemoteFileToQiNiu", method = RequestMethod.POST)
    public String uploadRemoteFileToQiNiu( @ApiParam(name = "fileUrl", value = "文件地址", required = true) @RequestParam("fileUrl") String fileUrl) throws MyException {
        return fileService.uploadRemoteFileToQiNiu(fileUrl);
    }

    @ApiOperation(value = "上传本地文件到七牛", notes = "上传本地文件到七牛")
    @RequestMapping(value = "/uploadLocalFileToQiNiu", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
	public String uploadLocalFileToQiNiu(@ApiParam(name = "file", value = "文件", required = true) @RequestParam("file") MultipartFile file) throws MyException {
    	return fileService.uploadLocalFileToQiNiu(file);
    }

}